package structuralPatterns.flyweight;

import java.util.HashMap;

public class FlyweightFactory {
    HashMap<Object,Flyweight> flyweights = new HashMap<Object,Flyweight>();

    public Flyweight getFlyweight(Object object){

        Flyweight flyweight = flyweights.get(object);
        if(flyweight == null){
            flyweight = new ConcreteFlyweight((String)object);
            flyweights.put(object,flyweight);
        }
        return flyweight;
    }

    public int getFlyweightSize(){
        return flyweights.size();
    }
}
